// example_text_file_writer.cpp : Defines the entry point for the console application.
//
/*
// Sync Routine
#include "stdafx.h"
#include <Inklude/ikCNetClientFactory.h>
#include <Windows.h>

using namespace Inklude;

int _tmain(int argc, _TCHAR* argv[])
{   
    std::shared_ptr<ikINetClient> pClient = ikCNetClientFactory::CreateClient(1007);
    pClient->Initialize(9999);
    char *buffer = new char[6000];

    while (true)
    {
        if (pClient->Receive(buffer, 6000) == 6000)
        {
            //sscanf_s(buffer, "this is #%d\n");
            printf(buffer);
        }
    }

	return 0;
}
*/


//Async Routine

#include "stdafx.h"
#include <Inklude/ikCNetClientFactory.h>
#include <Windows.h>

using namespace Inklude;
int _tmain(int argc, _TCHAR* argv[])
{   
    auto client = ikCNetClientFactory::CreateClient(Inklude::NET_OPTION::TCP_ASYNC);
    char *buffer = new char[60000];

    ikINetClient::AsyncHandler handler;

    handler.reset(new std::function<void(size_t)>([&](size_t recvSize)
    {
        printf(buffer);
        client->Receive(buffer, 6000, handler);
    }
    ));

    client->Initialize(9999);
    client->Receive(buffer, 6000, handler);

    while (true)
    {
        Sleep(1000);
        printf("SERVER main thread\n");
    }

	return 0;
}

